//
//  DateExtension.swift
//  DateNote
//
//  Created by 杨立鹏 on 2018/3/25.
//  Copyright © 2018年 杨立鹏. All rights reserved.
//

import Foundation

import SwifterSwift
extension Date {
    
    func formatString (_ format: String) -> String {
        
        let dateFormatter = DateFormatter()
        dateFormatter.locale = Locale.current
        dateFormatter.timeZone = TimeZone.current
        dateFormatter.dateFormat = format
        
        return dateFormatter.string(from: self)
    }
    
    var timeZhFormat: String {
        
        if self.isInToday {
            
            return formatString("HH:mm")
        }
        if self.isInYesterday {
            return "昨天 \(formatString("HH:mm"))"
        }
        if self.isInCurrentYear {
            return formatString("MM-dd HH:mm")
        }
        return formatString("yyyy-MM-dd HH:mm")
    }
    
}
